package com.springboot.mybatis.service.single;

/**
 * @author sunyt31481
 * @date 2020/8/27 13:56
 * @description 懒汉式
 */
public class Lazy {
   /* private static Lazy instance;
    private Lazy(){}
    public static synchronized Lazy getInstance() {
        if (instance == null) {
            instance = new Lazy();
        }
        return instance;
    }*/

    //加双重校验锁，DCL
/*
    private volatile static Lazy lazy;
    private Lazy (){}
    public static Lazy getSingleton() {
        if (lazy == null) {
            synchronized (Lazy.class) {
                if (lazy == null) {
                    lazy = new Lazy();
                }
            }
        }
        return lazy;
    }
*/

    //静态内部类
    private static class SingletonHolder {
        private static final Lazy INSTANCE = new Lazy();
    }
    private Lazy (){}
    public static final Lazy getInstance() {
        return SingletonHolder.INSTANCE;
    }
}
